package com.credit.jumu.calculator.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.widget.EditText;
import android.widget.TextView;

import com.credit.jumu.calculator.R;
import com.credit.jumu.calculator.activity.OtherResultActivity_;
import com.credit.jumu.calculator.base.BaseFragment;
import com.credit.jumu.calculator.utils.DensityUtil;
import com.credit.jumu.calculator.utils.LogUtils;
import com.credit.jumu.calculator.utils.StringHandleUtil;
import com.credit.jumu.calculator.utils.ToastUtil;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import cn.qqtheme.framework.picker.OptionPicker;
import cn.qqtheme.framework.widget.WheelView;

/**
 * Created by Administrator on 2017/11/24/024.
 */
//混合贷
@EFragment(R.layout.fragment_blend)
public class BlendFragment extends BaseFragment {
	@ViewById
	TextView blendtype;
	@ViewById
	TextView blendlilv;
	int type = 0;
	@ViewById
	EditText allmoney1, lilv1, allmoney2, lilv2, blendyears;
	double[] lilvbei = {1.3, 1.2, 1.1, 1, 0.95, 0.9, 0.85, 0.8, 0.7};


	@Override
	public void onResume() {
		super.onResume();
		LogUtils.println("-----------------------BlendFragmentonResume");
		hideKeyboard();
	}

	@Override
	public void onPause() {
		super.onPause();
		hideKeyboard();
		LogUtils.println("-----------------------BlendFragmentonPause");
	}

	@Override
	public void onStart() {
		super.onStart();
		LogUtils.println("-----------------------BlendFragmentonStart");
	}

	@Override
	public void onStop() {
		super.onStop();
		LogUtils.println("-----------------------BlendFragmentonStop");
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		LogUtils.println("-----------------------BlendFragmentonHiddenChanged");
	}

	@Click(R.id.togetresult)
	public void toResult() {

		double allmoney1d = StringHandleUtil.toInt(allmoney1.getText().toString());//总金额
		double lilv1d = StringHandleUtil.toInt(lilv1.getText().toString());//利率
		double allmoney2d = StringHandleUtil.toInt(allmoney2.getText().toString());//总金额
		double lilv2d = StringHandleUtil.toInt(lilv2.getText().toString());//利率
		int blendyearsd = StringHandleUtil.toInts(blendyears.getText().toString());//年限
		if (allmoney1d <= 0 || lilv1d <= 0 || allmoney2d <= 0 || lilv2d <= 0 || blendyearsd <= 0) {
			ToastUtil.showShortToast("请先完善信息");
			return;
		}
		Intent intent = new Intent(getActivity(), OtherResultActivity_.class);

		intent.putExtra("allmoney1", allmoney1d);
		intent.putExtra("lilv1", lilv1d);
		intent.putExtra("allmoney2", allmoney2d);
		intent.putExtra("lilv2", lilv2d);
		intent.putExtra("blendyearsd", blendyearsd);
		intent.putExtra("type", type);
		intent.putExtra("page", 2);
		startActivity(intent);
	}

	@Click(R.id.blendlilv)
	public void blendLilv() {
		OptionPicker picker = new OptionPicker(getActivity(), new String[]{
				"基本利率1.3倍", "基本利率1.2倍", "基本利率1.1倍", "基本利率"
				, "95折", "9折", "85折", "8折", "7折"
		});
		picker.setCycleDisable(true);//设置启用循环
		picker.setLineSpaceMultiplier(1);//总高度(1-4)
		picker.setCanceledOnTouchOutside(false);
		picker.setDividerRatio(WheelView.DividerConfig.FILL);
		picker.setShadowColor(Color.BLACK, 1);//选中的背景色
		picker.setSelectedIndex(0);
		picker.setTopLineColor(getResources().getColor(R.color.transparent));//分割线颜色
		picker.setSubmitTextColor(getResources().getColor(R.color.titlettextbg));//右边文字
		picker.setCancelTextColor(getResources().getColor(R.color.titlettextbg));//左边文字
		picker.setTextSize(DensityUtil.dip2px(getContext(), 7));//文字大小
		picker.setTextColor(getResources().getColor(R.color.back));
		picker.setDividerColor(getResources().getColor(R.color.transparent));
		picker.setTopBackgroundColor(getResources().getColor(R.color.linebg));//顶部背景
		picker.setSubmitText("完成");
		picker.setCanceledOnTouchOutside(true);
		picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
			@Override
			public void onOptionPicked(int index, String item) {
				blendlilv.setText(item);
				lilv2.setText(StringHandleUtil.toOnlyHavaTwo(lilvbei[index] * 4.9));
			}
		});
		picker.show();
	}

	@Click(R.id.blendtype)
	public void blendType() {
		OptionPicker picker = new OptionPicker(getActivity(), new String[]{
				"等额本息", "等额本金"
		});
		picker.setCycleDisable(true);//设置启用循环
		picker.setLineSpaceMultiplier(1);//总高度(1-4)
		picker.setCanceledOnTouchOutside(false);
		picker.setDividerRatio(WheelView.DividerConfig.FILL);
		picker.setShadowColor(Color.BLACK, 1);//选中的背景色
		picker.setSelectedIndex(0);
		picker.setTopLineColor(getResources().getColor(R.color.transparent));//分割线颜色
		picker.setSubmitTextColor(getResources().getColor(R.color.titlettextbg));//右边文字
		picker.setCancelTextColor(getResources().getColor(R.color.titlettextbg));//左边文字
		picker.setTextSize(DensityUtil.dip2px(getContext(), 7));//文字大小
		picker.setTextColor(getResources().getColor(R.color.back));
		picker.setDividerColor(getResources().getColor(R.color.transparent));
		picker.setTopBackgroundColor(getResources().getColor(R.color.linebg));//顶部背景
		picker.setSubmitText("完成");
		picker.setCanceledOnTouchOutside(true);
		picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
			@Override
			public void onOptionPicked(int index, String item) {
				type = index;
				blendtype.setText(item);
			}
		});
		picker.show();
	}


}
